package org.example.day;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2025/04/03 16:49
 */
public class Solution2874 {

    public static void main(String[] args) {
        System.out.println(new Solution2874().maximumTripletValue(new int[]{1000,1, 1000}));
    }


    public long maximumTripletValue(int[] nums) {
        long res = 0;
        int[] preMax = new int[nums.length];
        preMax[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            preMax[i] = Math.max(preMax[i-1], nums[i]);
        }
        int[] sufMax = new int[nums.length];
        sufMax[nums.length-1] = nums[nums.length-1];
        for (int i = nums.length - 2; i >= 0; i--) {
            sufMax[i] = Math.max(sufMax[i+1], nums[i]);
        }

        for (int i = 1; i < nums.length - 1; i++) {
            res = Math.max(res, (long) (preMax[i - 1] - nums[i]) * sufMax[i+1]);
        }
        return res;
    }

}
